package com.fast.fastenjoy.base.dao;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.persistence.Entity;

import org.springframework.orm.hibernate4.LocalSessionFactoryBean;

import com.fast.fastenjoy.base.utils.PackageUtils;

public class LocalSessionFactoryExBean extends LocalSessionFactoryBean{

	private List<String> annotatedClassPackageList;
	
	@PostConstruct
	public void init(){
		
		Set<Class<?>> classSet = PackageUtils.getClassName(Entity.class, annotatedClassPackageList);
		
		if(classSet != null){
			Class<?>[] classes = new Class[classSet.size()];
			
			Iterator<Class<?>> iterator = classSet.iterator();
			
			int i = 0;
			while(iterator.hasNext()){
				classes[i] = iterator.next();
				i++;
			}
			
			setAnnotatedClasses(classes);
		}
	}
	
	public List<String> getAnnotatedClassPackageList() {
		return annotatedClassPackageList;
	}

	public void setAnnotatedClassPackageList(List<String> annotatedClassPackageList) {
		this.annotatedClassPackageList = annotatedClassPackageList;
	}
	
}
